package com.handler.exception;


import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class ExceptionHandler implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object o, Exception e) {

        BaseException Exception = null;
        if(e instanceof BaseException){
            Exception = (BaseException) e;
        }else{
            Exception = new BaseException("未知错误",500,500);
        }

        ModelAndView mav = new ModelAndView();

        mav.addObject("message",Exception.getMessage());
        mav.addObject("code",Exception.getCode());
        mav.addObject("err_code",Exception.getErr_code());

        return mav;

    }
}
